package com.ftg.elvis.controller;

import com.ftg.elvis.pojo.Comment;
import com.ftg.elvis.service.AdminCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/comment")
public class AdminCommentController {

	@Autowired
	AdminCommentService adminCommentService;

	@GetMapping("/showAll")
	public Map<String, Object> showAll(int page, int limit, String comment, String bname, String state){
		List<Comment> list =  adminCommentService.showAll(page, limit, comment, bname, state);
		Map<String, Object> map = new HashMap<>();
		map.put("comment", comment);
		map.put("bname", bname);
		map.put("state", state);
		map.put("code", 0);
		map.put("count", adminCommentService.getCount(comment, bname, state));
		map.put("data", list);
		return map;
	}

	@PostMapping("/reply")
	public int reply(String cid, String reply){
		return adminCommentService.reply(cid, reply);
	}

	@DeleteMapping("/del/{cid}")
	public int delete(@PathVariable String cid){
		return adminCommentService.delete(cid);
	}

}
